package org.goodev.recyclerviewfastscroll;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * Created on 2017/9/4.
 */

public class DemoAdapter extends RecyclerView.Adapter<DemoAdapter.Holder> {
    final Context mContext;
    final String[] mItems;
    final View.OnClickListener mListener;
    public DemoAdapter(Context context, View.OnClickListener listener) {
        mListener = listener;
        mContext = context;
        mItems = context.getResources().getStringArray(R.array.items);
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(mContext);
        View view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
        view.setOnClickListener(mListener);
        return new Holder(view);
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {
        holder.bind(mItems[position]);
    }

    @Override
    public int getItemCount() {
        return mItems.length;
    }

    static class Holder extends RecyclerView.ViewHolder {
        public Holder(View itemView) {
            super(itemView);
        }

        public void bind(String item) {
            ((TextView)itemView).setText(item);
        }
    }

}
